Skip to content

Conversation

@Yu-zh
Copy link
Collaborator

@Yu-zh Yu-zh commented Oct 30, 2025

This PR Implements MutArrayView[T], a zero-copy mutable view type that provides read-write access to array slices without copying data.

Major Changes:

  • New type: MutArrayView[T] - a builtin valtype representing a mutable window into arrays
  • Core operations:
    • Element access: at()/[] and set()/[]= with bounds checking
    • Unsafe operations: unsafe_get() and unsafe_set() for performance-critical code
    • View creation: mut_sub() method for Arrays, FixedArrays, and MutArrayViews
    • Read-only conversion: sub()/[:] to convert to immutable ArrayView
  • Iterator support: Added iterator(), rev_iterator(), and iterator2() implementations
  • Trait implementations: Show, Eq, Compare, and Hash
  • Negative index support: Enables Python-style negative indexing (e.g., arr.mut_sub(start=-3, end=-1))
  • For the rest of APIs that ArrayView[T] has but not implemented for MutArrayView[T], user can first take view from MutArrayView[T] and then use ArrayView[T]'s API.

@Yu-zh Yu-zh marked this pull request as draft October 30, 2025 02:48
@Yu-zh Yu-zh marked this pull request as ready for review October 31, 2025 05:40
@coveralls
Copy link
Collaborator

coveralls commented Oct 31, 2025

Pull Request Test Coverage Report for Build 1911

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 40 of 75 (53.33%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 91.321%

Changes Missing Coverage Covered Lines Changed/Added Lines %
builtin/arrayview.mbt 5 20 25.0%
builtin/mutarrayview.mbt 35 55 63.64%
Totals Coverage Status
Change from base Build 1907: -0.2%
Covered Lines: 10333
Relevant Lines: 11315

💛 - Coveralls

@Yu-zh Yu-zh marked this pull request as draft October 31, 2025 07:41
@Yu-zh Yu-zh marked this pull request as ready for review November 17, 2025 03:38
@Yu-zh
Copy link
Collaborator Author

Yu-zh commented Nov 17, 2025

Update:

  • Added a commit that moves some relevant definition of ArrayView to builtin
  • Moves all the MutArrayView definition to builtin as well

@bobzhang bobzhang enabled auto-merge (rebase) November 17, 2025 13:08
@bobzhang bobzhang merged commit 4e58648 into main Nov 17, 2025
14 checks passed
@bobzhang bobzhang deleted the mut-array-view branch November 17, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants